package demo2;

import java.util.Stack;

public class Test {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] pushA = {1,2};
        int[] popA = {1};
        System.out.println(solution.IsPopOrder(pushA, popA));

    }
}


class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack <Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while(j < popA.length && !stack.empty() && stack.peek().equals(popA[j])) {
                stack.pop();
                j++;
            }
        }
        if (j == popA.length) {
            return stack.empty();
        }
        return false;
    }
}
